package com.xcdh.trading.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcdh.commons.annotation.XCDHAspect;
import com.xcdh.commons.controller.BaseController;
import com.xcdh.commons.query.QueryItemPayload;
import com.xcdh.commons.query.QueryPayload;
import com.xcdh.commons.spring.aspect.XCDHHTTPRequestLog;
import com.xcdh.domain.vo.PageVO;
import com.xcdh.domain.vo.R;
import com.xcdh.trading.entity.DayTransactionData;
import com.xcdh.trading.entity.HotMoneyTrc;
import com.xcdh.trading.entity.StockInfo;
import com.xcdh.trading.service.DayTransactionDataService;
import com.xcdh.trading.service.HotMoneyTrcService;
import com.xcdh.trading.util.ColumnTrItem;
import com.xcdh.trading.util.ColumnTrUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/day-transaction-data")
public class DayTransactionDataController extends BaseController<DayTransactionData ,DayTransactionDataService > {

    @Autowired
    private DayTransactionDataService dayTransactionDataService;
    @Autowired
    private HotMoneyTrcService hotMoneyTrcService ;

    @PostMapping("/syncTransactionData/{dataCode}")
    public R syncTransactionData(@PathVariable String dataCode){
        dayTransactionDataService.syncTransactionData(dataCode);
        return R.ok();
    }

    @PostMapping("/countTransactionData/{dataCode}")
    public R countTransactionData(@PathVariable String dataCode){
        dayTransactionDataService.countTransactionData(dataCode);
        return R.ok();
    }



    @PostMapping("/xGuList")
    public R<PageVO<DayTransactionData>> xGuList(@RequestBody QueryPayload queryPayload){
        List<QueryItemPayload> items = queryPayload.getItems();
        if(items != null){
            List<QueryItemPayload> list = items.stream().filter(item -> !StringUtils.equals(item.getKey(), "tradeDate"))
                    .collect(Collectors.toList());
            queryPayload.setItems(list);
        }
        IPage<DayTransactionData> result = dayTransactionDataService.xGuList(queryPayload.getPageDto(DayTransactionData.class),
                queryPayload.getQueryWrapper(DayTransactionData.class , false));
        List<String> list = result.getRecords().stream()
                .map(DayTransactionData::getTsCode).collect(Collectors.toList());
        return R.page(result);
    }



}
